$(document).ready(function() {
	console.log("scoreline.js start");
	getScore();
	//返回首页
	$("#imageBt").click(function(event) {
		window.location.href= "./home.html";
	});
});
function getScore(userid){
	$.ajax({
		url: '../test/getOwnScore',
		type: 'GET',
		dataType: 'json',
		data: {level: '0'},
		success: function(data){
			console.log("ajax success!!!");
			console.log(data.scoreList);
			console.log(data.percent);
			update(handleScore(data.scoreList),data.percent*100);
		},
		error: function(){
			console.log("ajax fail!!!");
			alert(errorThrown);
		}
	});
}

function handleScore(scores){
	var dataSet = {};
	var dataNum = 10;
	dataset = [];
	xMarks = [];
	var scoreLength = scores.length;
	for (var i = 0; i < dataNum; i++) {
		if(scoreLength<=10){
			if(i<scoreLength){
				dataset.push(scores[i]);
			}else{
				dataset.push(0);
			}
		}else if(scoreLength>10){
			dataset.push(scores[scoreLength - 10 + i]);
		}
		xMarks.push(i+1);
	}
	dataSet.dataset = dataset;
	dataSet.xMarks = xMarks;
	return dataSet;
}